/* Encodes the given graph and pebbles in PSVN.

   Let N be the number of nodes (1 <= N <= 15), E the number of edges, and
   P the number of pebbles (1 <= P <= N - 1). 

   Input format:
   N E
   (E lines, each with integers A B denoting edge (A, B).
   P
   (P integers, the ith of which is the goal node for pebble i). 

   See pebble3x3 (a graph version of the sliding 3x3 puzzble) for an
   example.
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>

using namespace std;

void print_blanks(int n)
{
    for (int i = 0; i < n; ++i)
        printf("- ");
}

void print_edge(int N, int a, int b, char x, char y)
{
    print_blanks(a);
    printf("%c ", x);
    print_blanks(b - a - 1);
    printf("%c ", y);
    print_blanks(N - b - 1);
    printf("=> ");
    print_blanks(a);
    printf("%c ", y);
    print_blanks(b - a - 1);
    printf("%c ", x);
    print_blanks(N - b - 1);
    printf("\n");
}

void error(const char* str)
{
    fprintf(stderr, "%s\n", str);
    exit(1);
}

int main()
{
    int N, E, P;
    bool graph[32][32];
    int pebble[32];
    memset(graph, 0, sizeof(graph));
    memset(pebble, -1, sizeof(pebble));
    scanf(" %d", &N);
    if (N < 1 || N > 15)
        error("bad number of nodes");
    scanf(" %d", &E);
    for (int i = 0; i < E; ++i) {
        int a, b;
        scanf(" %d %d", &a, &b);
        graph[a][b] = true;
        graph[b][a] = true;
    }
    scanf(" %d", &P);
    if (P < 1 || P > N - 1)
        error("bad number of pebbles");
    for (int i = 0; i < P; ++i) {
        int g;
        scanf(" %d", &g);
        if (g < 0 || g >= N)
            error("bad goal");
        if (pebble[g] != -1)
            error("duplicate goal");
        pebble[g] = i;
    }
    printf("domain node %d b", P + 1);
    for (int i = 0; i < P; ++i)
        printf(" %d", i + 1);
    printf("\n");
    printf("%d\n", N);
    for (int i = 0; i < N; ++i)
        printf("node ");
    printf("\n\n");
    for (int a = 0; a < N; ++a) {
        for (int b = a + 1; b < N; ++b) {
            if (!graph[a][b])
                continue;
            print_edge(N, a, b, 'X', 'b');
            print_edge(N, a, b, 'b', 'X');
        }
    }
    printf("goal ");
    for (int i = 0 ; i < N; ++i) {
        if (pebble[i] == -1)
            printf("b ");
        else
            printf("%d ", pebble[i] + 1);
    }
    printf("\n");
    return 0;
}
